#!usr/bin/python3
import sys
import getopt
import os
import shutil


def getFilePathFromDir(src, target):
    for dirpath, dirnames, filenames in os.walk(src):
        print("当前目录为:{}".format(dirpath))
        relativePath = dirpath[len(src):]
        print("relativePath:"+relativePath)
        for dir in dirnames:
            if dir[0] == "." or (len(relativePath) > 0 and relativePath[1] =="."):
                continue
            os.mkdir(target  +relativePath +"/" + dir)
            print("需要创建的文件夹为：" + target + relativePath + "/" + dir)
        for file in filenames:
            if file[0] == '.' or (len(relativePath) > 0 and relativePath[1] =="."):
                continue
            handler = target + relativePath + "/" + file.replace(".", "_") + ".md"
            open(handler,'w').close()
            print("需要创建的文件为：" + handler)

        pass


if __name__ == '__main__':
    getFilePathFromDir("/Users/shu/personal_data/leand/android/CustomView", "/Users/shu/Downloads/test")
    # str = "sk.sjfla.fljas"
    # print("str :{} ,target :{}".format(str.replace(".", "_") + ".md", str))
    # tar = "/Users/shu/personal_data/leand/android/CustomView"
    # src = "/Users/shu/personal_data/leand/android/CustomView"
    # print(src[len(tar) + 1:])
    # open("/Users/shu/Downloads/test/yangshu.md", 'w').close();
